import Mock from "mockjs";

// 生成充电桩订单列表
var dataList = [];
for (let i = 0; i < 40; i++) {
  let id = Mock.Random.id();
  dataList.push(
    Mock.mock({
      // id: id,
      // ctime: date,
      // ftime: '@date("yyyy-MM-dd HH:mm:ss")',
      // sn: "智能液晶屏充电桩-G433712",
      // userName: "@title(2,3)",
      payManner: "微信支付",
      // payMoney: 0,
      address: "云禾智能",
      // payId: '@date("yyyyMMddHHmmss")' + "PQ000000G433720MSP",
      // phone: /^1[34578]\d{9}$/,
    })
  );
}

let devList = ["G433704", "G433712", "G433720", "G433708"];
let userNameList = [
  "*海阔天空",
  "代价是折磨╳",
  "焚心劫",
  "◆乱世梦红颜",
  "有你，很幸福",
  "哭花了素颜、",
  "昂贵的、背影",
  "淡淡の、清香",
  "迷路的男人",
  "虚伪了的真心",
  "笑叹★尘世美",
  "ー 半 忧 伤",
  "回忆未来",
  "←极§速",
  "雁過藍天",
  "、尓蕞紾貴",
  "始终ē∫桓鋈似嗔供d",
  "|宝贝雪儿|",
  "超越梦想",
  "╰飞つ",
  "sonny非她不",
  "嘜瀦",
  "中华英雄",
  "纯洁的半烟",
  "∩千里之外し",
  "峰回路转",
  "白帆",
  "唯独钟情于你",
  "褪蘟※茳餬",
  "温柔一脚",
  "要烦",
  "尘梦如烟",
  "︶ㄣ莣孒ㄣ",
  "落叶知秋",
  "King.",
  "『我心永恒』",
  "淤淤",
  "无语",
  "Mr小华",
  "椰风",
  "╰★╮闆塼",
  "▂_倥絔",
  "余温散尽 ぺ",
  "莫名的青春",
  "Edinburgh° 南空",
  "■　孤独像过不去的桥　≈",
  "拥菢过后、只剰凄凉→＼",
  "别在我面前犯贱",
  "＊巴黎铁塔",
  "念安． я",
  "、あ浅浅の嘚僾",
  "蔚蓝的天空〃没有我的翅膀",
  "在哪跌倒こ就在哪躺下",
];

var standardTime = new Date();

dataList.forEach((v, i) => {
  function add(params) {
    return params < 10 ? "0" + params : params;
  }

  userNameList.forEach((u, j) => {
    if (i === j) v.userName = u;
  });
  let year = standardTime.getFullYear();
  let month = add(standardTime.getMonth() + 1);
  let date = add(standardTime.getDate()); //获取当前日(1-31)
  date = add((1 + Math.floor(Math.random() * date)).toFixed());
  let hour = add(Math.floor(Math.random() * 24).toFixed());
  let minute = add(Math.floor(Math.random() * 60).toFixed());
  let second = add(Math.floor(Math.random() * 60).toFixed());

  let ftime_minute = add(Math.floor(Math.random() * 60).toFixed());
  let ftime_second = add(Math.floor(Math.random() * 60).toFixed());

  let sum = (3 + Math.floor(Math.random() * 4)).toFixed(); // 结束时间计算

  let ftime_hour = add(Number(hour) + Number(sum));

  let differ_hour = Number(ftime_hour) - Number(hour); //相差多少小时
  let decimals = Math.random().toFixed(2); // 小数

  v.payMoney = Number(differ_hour) + Number(decimals); //支付金额

  let finally_hour =
    Number(ftime_hour) >= 24 ? add(Number(ftime_hour) - 24) : ftime_hour;

  let finally_date = Number(ftime_hour) >= 24 ? add(Number(date) + 1) : date;

  v.ctime = `${year}-${month}-${date} ${hour}:${minute}:${second}`; // 开始时间

  v.timestamp = Date.parse(new Date(v.ctime));

  v.ftime = `${year}-${month}-${finally_date} ${finally_hour}:${ftime_minute}:${ftime_second}`;

  v.id =
    "165" + Math.floor(Math.random() * 8999999999999 + 1000000000000).toFixed();

  let id_firstNum = v.id.substr(v.id.length - 1, 1);
  v.sn = `智能液晶屏充电桩-${
    id_firstNum < 2
      ? devList[0]
      : id_firstNum < 4
      ? devList[1]
      : id_firstNum < 6
      ? devList[2]
      : devList[3]
  }`;

  v["payId"] =
    `${year}${month}${date}${hour}${minute}${second}PQ000000${
      v.sn.split("-")[1]
    }` + "MSP"; // 交易单号
});
// 排序
function compare(timestamp) {
  return function (a, b) {
    var value1 = a[timestamp];
    var value2 = b[timestamp];
    return value1 - value2;
  };
}
dataList.sort(compare("timestamp"));

export function order_list() {
  return {
    // isOpen: false,
    url: "/sys/chargingPile/orderList",
    type: "get",
    data: {
      msg: "success",
      code: 0,
      page: {
        total: dataList.length,
        pageSize: 10,
        totalPage: 1,
        currPage: 1,
        list: dataList,
      },
    },
  };
}
